import { BaseWindow } from "../../../../component/window/BaseWindow";
import { Language } from "../../../../../extend/language/Language";
import { SPetSkill } from "../../../../../Message/Game/SPetSkill";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { SkillConfig } from "../../../resource/SkillConfig";
import { ColorConfig } from "../../../resource/ColorConfig";
import { PetUtil } from "../info/PetUtil";
import { ShopConfig } from "../../../resource/ShopConfig";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../Message/Public/EProp";
import { ObjCreate } from "../../common/ObjCreate";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { BuyCommonPanel } from "./BuyCommonPanel";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { MsgManager } from "../../../manager/MsgManager";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { ItemData } from "../../../resource/info/ItemData";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
//class DigConfirmWindow
    
    export  class DigConfirmWindow extends BaseWindow
    {
        constructor()
        {
            super();
            setSize(330, 240);
            this.titleHeight = 28;
            title = Language.getString(54129);
            return;
        }

        public updateData(arg1: SPetSkill, arg2: SPetInfo, arg3: Function=null): void
        {
            var loc1=null;
            var loc4=null;
            var loc2=1;
            var loc3;
            if (loc3 = SkillConfig.instance.getInfoByName(arg1.skillId)) 
            {
                loc2 = loc3.skillLevel;
            }
            loc4 = ColorConfig.instance.getItemColorString(loc2 + 1);
            this._infoTxt.htmlText = Language.getStringByParam(54448, loc4, loc3.skillName);
            if (arg2) 
            {
                loc1 = PetUtil.getPetName(arg2);
            }
            this._digProp = ShopConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropPetSkillDig, loc2);
            this._buyPanel.updateByShopItemInfo(this._digProp);
            DigConfirmWindow.clickHandler = arg3;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._digProp = ShopConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropPetSkillDig);
            ObjCreate.createBg(17, 40, 293, 145, this);
            this.addChild(new GImageBitmap("petDigIcon.png", 245, 40));
            this._infoTxt = ObjCreate.createTextField("", 25, 45, 300, 20, this);
            this._infoTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._buyPanel = new BuyCommonPanel();
            this._buyPanel.x = 35;
            this._buyPanel.y = 110;
            this._buyPanel.updateByShopItemInfo(this._digProp);
            this.addChild(this._buyPanel);
            this._okBtn = ObjCreate.createGButton(Language.getString(54065), 60, 190, 60, 24, this);
            this._okBtn.name = "ok";
            this._cancelBtn = ObjCreate.createGButton(Language.getString(54066), 170, 190, 60, 24, this);
            this._cancelBtn.name = "cancel";
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            ObjCreate.createTextField(Language.getString(54449), 25, 215, 200, 20, this, GlobalStyle.textFormat5);
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=(arg1.target as GButton).name;
            if (loc1 != "ok") 
            {
                this._isOk = false;
            }
            else 
            {
                this._isOk = true;
            }
            if (DigConfirmWindow.clickHandler != null) 
            {
                this._propItemData = this._buyPanel.getToUseItemData();
                if (this._isOk) 
                {
                    if (this._propItemData == null) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54199) + ItemsUtil.getItemName(this._buyPanel.itemData));
                        return;
                    }
                }
                DigConfirmWindow.clickHandler(this._isOk, this._propItemData);
            }
            return;
        }

        public get isOk(): Boolean
        {
            return this._isOk;
        }

        /* internal */ /* var */_infoTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_buyPanel: BuyCommonPanel;

        /* internal */ /* var */_isOk: Boolean;

        /* internal */ /* var */_propItemData: ItemData;

        /* internal */ /* var */_digProp: ShopItemInfo;

        public static /* var */clickHandler: Function;
    }
